package com.alameda.filestorage.controller;

import com.alameda.filestorage.business.service.FileStorageComponent;
import org.dromara.x.file.storage.core.FileInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

/**
 * 文件上传 前端控制层
 *
 * @author Lv
 * @date 2024/11/23
 */
@RestController
@RequestMapping("/file")
public class FileStorageController {

    @Autowired
    private FileStorageComponent fileStorageComponent;

    /**
     * 上传文件
     *
     * @param multipartFile 文件对象
     * @return 文件信息
     */
    @PostMapping("/upload")
    public FileInfo upload(MultipartFile multipartFile) {
        return fileStorageComponent.upload(multipartFile);
    }

    /**
     * 上传图片
     *
     * @param multipartFile 文件对象
     * @return 文件信息
     */
    @PostMapping("/upload_image")
    public FileInfo uploadImage(MultipartFile multipartFile) {
        return fileStorageComponent.uploadImage(multipartFile);
    }

    /**
     * 上传文件
     *
     * @param request http请求对象
     * @return 文件信息
     */
    @PostMapping("/upload_request")
    public FileInfo uploadPlatform(HttpServletRequest request) {
        return fileStorageComponent.uploadPlatform(request);
    }
}
